#include "cdecl.h"
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <Comunicador.h>
/*
 * Define macros to specify the standard C calling convention
 * The macros are designed so that they will work with all
 * supported C/C++ compilers.
 *
 * To use define your function prototype like this:
 *
 * return_type PRE_CDECL func_name( args ) POST_CDECL;
 *
 * For example:
 *
 * int PRE_CDECL f( int x, int y) POST_CDECL;
 */

/*ASM declaraciones de funciones*/
int PRE_CDECL initRS(int COM) POST_CDECL;
int PRE_CDECL statusRS(int COM) POST_CDECL;
int PRE_CDECL sendRS(int COM, int sendChar) POST_CDECL;
int PRE_CDECL recvRS(int COM) POST_CDECL;
int PRE_CDECL print_s(int COM) POST_CDECL;
 
// int get_statuscode(int codigo);

/* Posible declaracion de metodos de jni:*/
  JNIEXPORT jint JNICALL Java_sistcomptf_Comunicador_initRS232C
  (JNIEnv *env, jobject obj, jint COM)
/*JNIEXPORT jint JNICALL 
Java_Comunicador_initRS232C(JNIEnv *env, jobject obj, jint COM)*/
{
  int ret_status, codigo_status_java;

  ret_status = initRS(COM);
  //codigo_status_java = get_statuscode(ret_status);

  //return codigo_status_java;
  return ret_status;
}

JNIEXPORT jint JNICALL 
Java_sistcomptf_Comunicador_statusRS232C(JNIEnv *env, jobject obj, jint COM)
{
  int ret_status, codigo_status_java;

  ret_status = statusRS(COM);
  //codigo_status_java = get_statuscode(ret_status);

  //return codigo_status_java;
   return ret_status;
}

JNIEXPORT jint JNICALL 
Java_sistcomptf_Comunicador_sendRS232C(JNIEnv *env, jobject obj, jint COM, jint sendChar)
{
  int ret_status;

  ret_status = sendRS(COM, sendChar);
 // codigo_status_java = get_statuscode(ret_status);

  return ret_status;
}

JNIEXPORT jint JNICALL 
Java_sistcomptf_Comunicador_recvRS232C(JNIEnv *env, jobject obj, jint COM)
{
  int ret_status, codigo_status_java;
  int recv;

  ret_status = recvRS(COM);
//Enmascaro lo recivido
  recv = ret_status&0x00ff;

  //codigo_status_java = get_statuscode(ret_status);

  return recv;
}

  JNIEXPORT jint JNICALL Java_sistcomptf_Comunicador_printRS232C
  (JNIEnv *env, jobject obj){
   int ret_status;

  ret_status = print_s(8);
  //codigo_status_java = get_statuscode(ret_status);

  //return codigo_status_java;
  return ret_status;
  }
  
    JNIEXPORT jint JNICALL Java_sistcomptf_Comunicador_printParam
  (JNIEnv *env, jobject obj, jint COM){
   int ret_status;

  ret_status = print_s(COM);
  //codigo_status_java = get_statuscode(ret_status);

  //return codigo_status_java;
  return ret_status;
  }
